import axios from 'axios';
import { AnyObject } from '@/types/global';

const url = '/adminapi/database/';

export interface ExportState {
  numbers: number | string;
  Name: string;
  Rows: string;
  'Data_length': string;
  Collation: string;
  'Create_time': string;
  Comment: string;
  status: string;
}

export interface ImportState {
  numbers: number | string;
  name: string;
  part: number;
  compress: string;
  size: string;
  mtime: string;
  time: string;
  filepath: string;
  'full_filepath': string;
}

export interface ExportListRes {
  data: ExportState[];
}

export interface ImportListRes {
  data: ImportState[];
}

/**
 * 备份列表
 */
export function apiExportList(params: AnyObject) {
  return axios.get<ExportListRes>(`${url}exportList`, { params });
}

/**
 * 备份
 */
export function apiExport(params: AnyObject) {
  return axios.post(`${url}doExport`, params);
}

/**
 * 优化表
 */
export function apiOptimize(params: AnyObject) {
  return axios.post(`${url}optimize`, params);
}

/**
 * 修复表
 */
export function apiRepair(params: AnyObject) {
  return axios.post(`${url}repair`, params);
}

/**
 * 还原列表
 */
export function apiImportList(params: AnyObject) {
  return axios.get<ImportListRes>(`${url}importList`, { params });
}

/**
 * 还原
 */
export function apiImport(params: AnyObject) {
  return axios.post(`${url}doImport`, params);
}

/**
 * 删除备份文件
 */
export function apiDel(params: AnyObject) {
  return axios.get(`${url}delete`, { params });
}

/**
 * 查看表结构
 */
export function apiView(params: AnyObject) {
  return axios.get(`${url}view`, { params });
}